


//
//  UIViewController+Commom.m
//  PostDelivery
//
//  Created by wmz on 2020/7/3.
//  Copyright © 2020 wmz. All rights reserved.
//

#import "UIViewController+Commom.h"

@implementation UIViewController (Commom)
//返回按钮
- (void)customBack:(NSString*)name{
    if (self.navigationController.viewControllers.count <= 1) return;
    self.navigationItem.hidesBackButton = YES;
    UIImage* backImg = [[UIImage imageNamed:name] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithImage:backImg style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = item;
    self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}

- (void)backAction{
    NSArray *viewControllers = [self.navigationController viewControllers];
    if (1 <= viewControllers.count && 0 < [viewControllers indexOfObject:self]) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
@end
